package thread2;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class LevelOrder {
    public List<List<Integer>> levelOrder(Node root) {
        if (root == null) {
            return new ArrayList<>();
        }

        List<List<Integer>> val = new ArrayList<>();
        Queue<Node> queue = new ArrayDeque<>();
        queue.offer(root);

        while (!queue.isEmpty()) {
            int size = queue.size();
            List<Integer> v = new ArrayList<>();
            for (int i = 0; i < size; i++) {
                Node temp = queue.poll();
                if (temp != null) {
                    v.add(temp.val);
                    List<Node> children = temp.children;
                    for (Node node : children) {
                        if (node != null) {
                            queue.offer(node);
                        }
                    }
                }
            }

            val.add(v);
        }

        return val;
    }

    public static void main(String[] args) {
        Node node5 = new Node();
        node5.val = 5;
        node5.children = null;

        Node node6 = new Node();
        node6.val = 6;
        node6.children = null;


    }
}
